home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / sun / awt / image / Image.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  4.9 KB  |  336 lines

  1. package sun.awt.image;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Graphics;
  6. import java.awt.image.ImageObserver;
  7. import java.awt.image.ImageProducer;
  8. import java.util.Enumeration;
  9. import java.util.Hashtable;
  10.  
  11. public abstract class Image extends java.awt.Image {
  12.    ImageProducer source;
  13.    InputStreamImageSource src;
  14.    ImageInfoGrabber info;
  15.    private int width = -1;
  16.    private int height = -1;
  17.    private Hashtable properties;
  18.    private int availinfo;
  19.    Hashtable representations = new Hashtable();
  20.    ImageRepresentation baseIR;
  21.  
  22.    protected Image() {
  23.    }
  24.  
  25.    protected Image(int var1, int var2) {
  26.       OffScreenImageSource var3 = new OffScreenImageSource((Component)null, var1, var2);
  27.       this.source = var3;
  28.       this.width = var1;
  29.       this.height = var2;
  30.       this.availinfo |= 3;
  31.       ImageRepresentation var4 = this.getImageRep(-1, -1);
  32.       this.representations.put(var1 + "x" + var2, var4);
  33.       this.representations.put("-1x-1", var4);
  34.       var4.setDimensions(var1, var2);
  35.       var4.offscreenInit102();
  36.       var3.setImageRep(var4);
  37.    }
  38.  
  39.    protected Image(Component var1, int var2, int var3) {
  40.       OffScreenImageSource var4 = new OffScreenImageSource(var1, var2, var3);
  41.       this.source = var4;
  42.       this.width = var2;
  43.       this.height = var3;
  44.       this.availinfo |= 3;
  45.       ImageRepresentation var5 = this.getImageRep(-1, -1);
  46.       this.representations.put(var2 + "x" + var3, var5);
  47.       this.representations.put("-1x-1", var5);
  48.       this.baseIR = var5;
  49.       var5.setDimensions(var2, var3);
  50.       var5.offscreenInit(var1.getBackground());
  51.       var4.setImageRep(var5);
  52.    }
  53.  
  54.    protected Image(ImageProducer var1) {
  55.       this.source = var1;
  56.       if (var1 instanceof InputStreamImageSource) {
  57.          this.src = (InputStreamImageSource)var1;
  58.       }
  59.  
  60.       this.info = new ImageInfoGrabber(this);
  61.       this.info.setupConsumer();
  62.    }
  63.  
  64.    public ImageProducer getSource() {
  65.       if (this.src != null) {
  66.          this.src.checkSecurity((Object)null, false);
  67.       }
  68.  
  69.       return this.source;
  70.    }
  71.  
  72.    protected void initGraphics(Graphics var1) {
  73.       OffScreenImageSource var2 = (OffScreenImageSource)this.source;
  74.       var1.setColor(var2.target.getForeground());
  75.       var1.setFont(var2.target.getFont());
  76.    }
  77.  
  78.    public Color getBackground() {
  79.       OffScreenImageSource var1 = (OffScreenImageSource)this.source;
  80.       return var1.target.getBackground();
  81.    }
  82.  
  83.    public int getWidth() {
  84.       if (this.src != null) {
  85.          this.src.checkSecurity((Object)null, false);
  86.       }
  87.  
  88.       if ((this.availinfo & 1) == 0) {
  89.          this.reconstruct(1);
  90.       }
  91.  
  92.       return this.width;
  93.    }
  94.  
  95.    public synchronized int getWidth(ImageObserver var1) {
  96.       if (this.src != null) {
  97.          this.src.checkSecurity((Object)null, false);
  98.       }
  99.  
  100.       if ((this.availinfo & 1) == 0) {
  101.          this.addWatcher(var1, true);
  102.          return -1;
  103.       } else {
  104.          return this.width;
  105.       }
  106.    }
  107.  
  108.    public int getHeight() {
  109.       if (this.src != null) {
  110.          this.src.checkSecurity((Object)null, false);
  111.       }
  112.  
  113.       if ((this.availinfo & 2) == 0) {
  114.          this.reconstruct(2);
  115.       }
  116.  
  117.       return this.height;
  118.    }
  119.  
  120.    public synchronized int getHeight(ImageObserver var1) {
  121.       if (this.src != null) {
  122.          this.src.checkSecurity((Object)null, false);
  123.       }
  124.  
  125.       if ((this.availinfo & 2) == 0) {
  126.          this.addWatcher(var1, true);
  127.          return -1;
  128.       } else {
  129.          return this.height;
  130.       }
  131.    }
  132.  
  133.    public Object getProperty(String var1, ImageObserver var2) {
  134.       if (this.src != null) {
  135.          this.src.checkSecurity((Object)null, false);
  136.       }
  137.  
  138.       if (this.properties == null) {
  139.          this.addWatcher(var2, true);
  140.          return null;
  141.       } else {
  142.          Object var3 = this.properties.get(var1);
  143.          if (var3 == null) {
  144.             var3 = java.awt.Image.UndefinedProperty;
  145.          }
  146.  
  147.          return var3;
  148.       }
  149.    }
  150.  
  151.    public boolean hasError() {
  152.       if (this.src != null) {
  153.          this.src.checkSecurity((Object)null, false);
  154.       }
  155.  
  156.       return (this.availinfo & 64) != 0;
  157.    }
  158.  
  159.    public int check(ImageObserver var1) {
  160.       if (this.src != null) {
  161.          this.src.checkSecurity((Object)null, false);
  162.       }
  163.  
  164.       if ((this.availinfo & 64) == 0 && (~this.availinfo & 7) != 0) {
  165.          this.addWatcher(var1, false);
  166.       }
  167.  
  168.       return this.availinfo;
  169.    }
  170.  
  171.    public void preload(ImageObserver var1) {
  172.       if (this.src != null) {
  173.          this.src.checkSecurity((Object)null, false);
  174.       }
  175.  
  176.       if ((this.availinfo & 32) == 0) {
  177.          this.addWatcher(var1, true);
  178.       }
  179.  
  180.    }
  181.  
  182.    private synchronized void addWatcher(ImageObserver var1, boolean var2) {
  183.       if ((this.availinfo & 64) != 0) {
  184.          if (var1 != null) {
  185.             var1.imageUpdate(this, 192, -1, -1, -1, -1);
  186.          }
  187.  
  188.       } else {
  189.          if (this.info == null) {
  190.             this.info = new ImageInfoGrabber(this);
  191.             this.info.setupConsumer();
  192.          }
  193.  
  194.          this.info.addWatcher(var1);
  195.          if (var2) {
  196.             this.info.getInfo();
  197.          }
  198.  
  199.       }
  200.    }
  201.  
  202.    private synchronized void reconstruct(int var1) {
  203.       if ((var1 & ~this.availinfo) != 0) {
  204.          if ((this.availinfo & 64) != 0) {
  205.             return;
  206.          }
  207.  
  208.          if (this.info == null) {
  209.             this.info = new ImageInfoGrabber(this);
  210.          }
  211.  
  212.          this.info.getInfo();
  213.  
  214.          while((var1 & ~this.availinfo) != 0) {
  215.             try {
  216.                this.wait();
  217.             } catch (InterruptedException var2) {
  218.                Thread.currentThread().interrupt();
  219.                return;
  220.             }
  221.  
  222.             if ((this.availinfo & 64) != 0) {
  223.                return;
  224.             }
  225.          }
  226.       }
  227.  
  228.    }
  229.  
  230.    synchronized void addInfo(int var1) {
  231.       this.availinfo |= var1;
  232.       this.notifyAll();
  233.       if ((~this.availinfo & 7) == 0) {
  234.          this.info.stopInfo();
  235.       }
  236.  
  237.    }
  238.  
  239.    void setDimensions(int var1, int var2) {
  240.       this.width = var1;
  241.       this.height = var2;
  242.       this.addInfo(3);
  243.    }
  244.  
  245.    void setProperties(Hashtable var1) {
  246.       if (var1 == null) {
  247.          var1 = new Hashtable();
  248.       }
  249.  
  250.       this.properties = var1;
  251.       this.addInfo(4);
  252.    }
  253.  
  254.    synchronized void infoDone(int var1) {
  255.       if (var1 != 1 && (~this.availinfo & 3) == 0) {
  256.          if ((this.availinfo & 4) == 0) {
  257.             this.setProperties((Hashtable)null);
  258.          }
  259.  
  260.       } else {
  261.          this.addInfo(64);
  262.       }
  263.    }
  264.  
  265.    public void flush() {
  266.       if (this.src != null) {
  267.          this.src.checkSecurity((Object)null, false);
  268.       }
  269.  
  270.       if (!(this.source instanceof OffScreenImageSource)) {
  271.          synchronized(this){}
  272.  
  273.          Enumeration var1;
  274.          try {
  275.             this.availinfo &= -65;
  276.             var1 = this.representations.elements();
  277.             this.representations = new Hashtable();
  278.             this.baseIR = null;
  279.             if (this.source instanceof InputStreamImageSource) {
  280.                ((InputStreamImageSource)this.source).flush();
  281.             }
  282.          } catch (Throwable var4) {
  283.             throw var4;
  284.          }
  285.  
  286.          while(var1.hasMoreElements()) {
  287.             ImageRepresentation var2 = (ImageRepresentation)var1.nextElement();
  288.             var2.abort();
  289.          }
  290.       }
  291.  
  292.    }
  293.  
  294.    protected ImageRepresentation getImageRep(int var1, int var2) {
  295.       if (this.src != null) {
  296.          this.src.checkSecurity((Object)null, false);
  297.       }
  298.  
  299.       String var3;
  300.       if ((var1 == -1 || var1 == this.width) && (var2 == -1 || var2 == this.height)) {
  301.          if (this.baseIR != null) {
  302.             return this.baseIR;
  303.          }
  304.  
  305.          var3 = "-1x-1";
  306.       } else {
  307.          var3 = var1 + "x" + var2;
  308.       }
  309.  
  310.       ImageRepresentation var4 = (ImageRepresentation)this.representations.get(var3);
  311.       if (var4 == null) {
  312.          synchronized(this){}
  313.  
  314.          try {
  315.             var4 = (ImageRepresentation)this.representations.get(var3);
  316.             if (var4 == null) {
  317.                var4 = new ImageRepresentation(this, var1, var2, 0);
  318.                if (this.source instanceof OffScreenImageSource) {
  319.                   var4.offscreen = true;
  320.                } else {
  321.                   this.representations.put(var3, var4);
  322.                }
  323.  
  324.                if (var1 == -1 && var2 == -1) {
  325.                   this.baseIR = var4;
  326.                }
  327.             }
  328.          } catch (Throwable var7) {
  329.             throw var7;
  330.          }
  331.       }
  332.  
  333.       return var4;
  334.    }
  335. }
  336.